package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Scenic;
import com.tour.service.impl.ScenicServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-01-18
 */
@Api(tags = "景区信息管理")
@RestController
@RequestMapping("/app/scenic")
public class ScenicController {

    @Autowired
    ScenicServiceImpl scenicService;

    @ApiOperation("添加某一个景区")
    @PostMapping("/addScenic")
    public ResponseWrapper addScenic(@RequestBody Scenic scenic){
        ResponseWrapper wrapper = scenicService.addScenic(scenic);
        return wrapper;
    }
    @ApiOperation("修改某一个景区")
    @PutMapping("/addScenic")
    public ResponseWrapper updateScenic(@RequestBody Scenic scenic){
        ResponseWrapper wrapper = scenicService.updateScenic(scenic);
        return wrapper;
    }
    @ApiOperation("删除景区")
    @ApiImplicitParam(name = "scenicId",value = "景区的id")
    @DeleteMapping("/deleteScenic")
    public ResponseWrapper deleteScenic(@RequestParam(name = "scenicId")Integer scenicId){
        ResponseWrapper wrapper = scenicService.deleteScenic(scenicId);
        return wrapper;
    }
    @ApiOperation("通过id查询一个景区")
    @ApiImplicitParam(name = "scenicId",value = "景区的id")
    @GetMapping("/findScenicById")
    public ResponseWrapper findScenicById(@RequestParam(name = "scenicId")Integer scenicId){
        ResponseWrapper wrapper = scenicService.findScenicById(scenicId);
        return wrapper;
    }
    @ApiOperation("按照热度查询景区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "city",value = "当前所在城市")
    })
    @GetMapping("/findScenicByReading")
    public ResponseWrapper findScenicByReading(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                               @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                               @RequestParam(name = "city",required = false)String city){
        ResponseWrapper wrapper = scenicService.findScenicByRead(pageSize,pageNum,city);
        return wrapper;
    }
    @ApiOperation("按照距离查询景区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户的id"),
            @ApiImplicitParam(name = "mylongitude",value = "用户的经度"),
            @ApiImplicitParam(name = "mylatitude",value = "用户的纬度"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "city",value = "当前所在城市")
    })
    @GetMapping("/findScenicByDistance")
    public ResponseWrapper findScenicByDistance(@RequestParam(name = "userId")Integer userId,
                                                @RequestParam(name = "mylongitude")Double mylongitude,
                                                @RequestParam(name = "mylatitude")Double mylatitude,
                                                @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                                @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                                @RequestParam(name = "city",required = false)String city){
        ResponseWrapper wrapper = scenicService.findScenicByDistance(userId,mylongitude,mylatitude,pageSize,pageNum,city);
        return wrapper;
    }

    @ApiOperation("查询某个景区的附近三个景区")
    @ApiImplicitParam(name = "scenicId",value = "景区的id")
    @GetMapping("/findNearScenic")
    public ResponseWrapper findNearScenic(@RequestParam(name = "scenicId")Integer scenicId){
        ResponseWrapper wrapper = scenicService.findNearScenic(scenicId);
        return wrapper;
    }
    @ApiOperation("模糊查询景区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scenicName",value = "搜索框搜索内容"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findScenicBySearch")
    public ResponseWrapper findScenicBySearch(@RequestParam(name = "scenicName",required = false)String scenicName,
                                              @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                              @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = scenicService.findScenicBySearch(scenicName,pageNum,pageSize);
        return wrapper;
    }

    @ApiOperation("图片上传")
    @PostMapping("/picUpload")
    public ResponseWrapper picUpload(@RequestParam("file") MultipartFile file) throws IOException {
        ResponseWrapper wrapper =scenicService.picUpload(file);
        return  wrapper;
    }
}

